define(['zepto', 'butterfly/view','../../bsl',
    'text!./maps_map.html'
], function($, View, bsl, maps_map) {
    var me = null;

    var view = View.extend({
        events: {

            // ！！！！ 由于 引入 touch.js 后，tap事件会变成双击，所以 本页面内不能使用tap，用click代替。
            "tap .openDoc" : "openDoc",
            "tap #back" : "back",

      
        },
        render: function() {
            me = this;
        },

        onShow: function() {

            // 绑定自定义事件 滑动切换日历等
             this.em=document.getElementById("map");
            window.plus&&plusReady(); 
            this.plusReady();          


        },
          ws:null,wo:null,
         em:null,map:null,
        // H5 plus事件处理
        plusReady:function (){
            if(!em||ws){return};
            // 获取窗口对象
            ws=plus.webview.currentWebview();
            wo=ws.opener();
            setTimeout(function(){
                map=new plus.maps.Map("map");
                map.centerAndZoom(new plus.maps.Point(116.3977,39.906016),12);
                createMarker();
                // 创建子窗口
                createSubview();
            },300);
            // 显示页面并关闭等待框
            ws.show("pop-in");
        },
        // if(window.plus){
        //     plusReady();
        // }else{
        //     document.addEventListener("plusready",plusReady,false);
        // }
        // // DOMContentloaded事件处理
        // document.addEventListener("DOMContentLoaded",function(){
        //     em=document.getElementById("map");
        //     window.plus&&plusReady();
        // },false);
        userLocation:function (){
            map.showUserLocation( true );
            map.getUserLocation(function(state,pos){
                if(0==state){
                    map.setCenter(pos);
                }
            });
        },
        createMarker:function (){
            var marker=new plus.maps.Marker(new plus.maps.Point(116.347496,39.970191));
            marker.setIcon("/logo.png");
            marker.setLabel("HBuilder");
            var bubble = new plus.maps.Bubble("打造最好的HTML5移动开发工具");
            marker.setBubble(bubble);
            map.addOverlay(marker);
        },
        createSubview:function (){
            if('Android'!=plus.os.name){
                return;
            }
            var wsub=plus.webview.create('maps_map_sub.html','sub',{top:'44px',height:'60px',position:'absolute',scrollIndicator:'none',background:'transparent'});
            ws.append(wsub);
        },
        resetMap:function (){
            map.centerAndZoom(new plus.maps.Point(116.3977,39.906016),12);
        },
          back : function(e){
            window.history.go(-1);
        },
        openDoc:function(){
             window.butterfly.navigate('/doc/events.html', {
                trigger: true
            });


        },
    
             
            });
    return view;
});
